package com.atmk.atmk.designMode.创建型.单例模式.饿汉式;
/*
* 静态代码块(可用，但可能造成内存浪费)
* */
public class Singleton2 {
    //1、私有化构造器，外部不能new
    private Singleton2() {
    }
    private static Singleton2 instance2;
    static {
        instance2 = new Singleton2();
    }
    public static Singleton2 getInstance2(){
        return instance2;
    }

    public static void main(String[] args) {
        Singleton2 instance1 = Singleton2.getInstance2();
        Singleton2 instance2 = Singleton2.getInstance2();
        System.out.println(instance1 == instance2);
        System.out.println("instance1.hashCode="+instance1.hashCode());
        System.out.println("instance2.hashCode="+instance2.hashCode());
    }
}
